#!/bin/bash

SCRIPT_DIR=$(cd `dirname $0` && pwd)
cd $SCRIPT_DIR

rm -rf ./_install

source config.busybox

rm -rf ./_install

if [ ! -f "${ARCHIVE}" ]; then
    wget "${MAIN_URL}"
    if [ $? !=0 ]; then
        wget "${MAIN_URL_ALT}"
        tar xvf "${ARCHIVE_ALT}"
    else
        tar xvf "${ARCHIVE}"
    fi
fi

if [ ! -f "${BUILD_FOLDER}" ]; then
    tar xvf "${ARCHIVE}"
    if [ $? !=0 ]; then
        tar xvf "${ARCHIVE_ALT}"
    fi
fi

cd "${BUILD_FOLDER}"

patch -p1 < ../gzdef.patch
patch -p1 < ../onvif.patch
patch -p1 < ../auth.patch

cp ../.config ./ || exit 1

